﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Design.Editors;
using ProgNetDxComponents.ExtenderProviders.Browsers;

namespace ProgNetDxComponents.Design.Editors
{
    public class BrowserColumnCollectionEditor : NamedCollectionEditor
    {
        public BrowserColumnCollectionEditor(Type type) : base(type) { }
        protected override bool GenerateConstantClass
        {
            get
            {
                return false;
            }
        }

        protected override void ValidateCollection(object collection)
        {
            BrowserColumnCollection coll = collection as BrowserColumnCollection;
            if (coll != null)
            {
                List<string> list = new List<string>();
                List<string> errors = new List<string>();
                foreach (BrowserColumn c in coll)
                {
                    if (c.Name.IsNull())
                    {
                        AddError("Not all columns have Name");
                    }
                    else
                    {
                        if (list.Contains(c.Name, StringComparer.InvariantCultureIgnoreCase))
                        {
                            AddError("Duplicated column " + c.Name.AddDoubleQuotes());
                        }
                        else
                            list.Add(c.Name);
                    }
                }
            }
        }
    }
}
